<?php

/**
 * Challenge Cup INDEX file,
 * @author Luke Barratt 
 * @copyright Copyright (C) 2008 by Luke Barratt
 * @license http://www.gnu.org/copyleft/gpl.html
 */

// Set flag that this is a parent file
define('CC_VALID', 1);

// Checks for configuration file, if none found loads installation page

if (!file_exists('config.php') || filesize('config.php') < 10)
{
    $self = rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . '/';
    header("Location: http://" . $_SERVER['HTTP_HOST'] . $self . "install/index.php");
    exit();
}

require_once ('config.php');

// SSL check

$http_host = explode(':', $_SERVER['HTTP_HOST']);
if ((!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off' ||
    isset($http_host[1]) && $http_host[1] == 443) && substr($CC_SITEURL, 0, 8) !=
    'https://')
{
    $CC_SITEURL = 'https://' . substr($CC_SITEURL, 7);
}

// Installation sub folder check

if (file_exists('installation/index.php'))
{
    define('CC_INSTALL', 1);
    include ($CC_ABSOLUTE . '/offline.php');
    exit();
}

// Check if the site has been disabled

if ($CC_STATUS == 0)
{
    require ($CC_ABSOLUTE . '/offline.php');
}

// Check to see if a URL parameter has been set

$CC_MOD = $_GET['mod'];
$CC_GAME_ID = $_GET['game_id'];
if ($CC_MOD == "") {
	header("Location: {$CC_SITEURL}/index.php?mod=news");
}

// Get template files

if (file_exists( $CC_ABSOLUTE .'/templates/'. $CC_TEMPLATE .'/index.php' )) {
	require_once( $CC_ABSOLUTE .'/templates/'. $CC_TEMPLATE .'/index.php' );
} else {
	require ($CC_ABSOLUTE . '/offline.php');
}

mysql_close();

?>